package cn.bugstack.domain.strategy.model.entity;

import cn.bugstack.types.common.Constants;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class StrategyEntity {
	/**
	 * 策略描述id
	 */
	private Long strategyId;
	/**
	 * 策略描述id
	 */
	private String strategyDesc;
	/**
	 * 规则模型，rule配置的模型同步到此表，便于使用
	 */
	private String ruleModels;

	public String[] ruleModels(){
		//isBlank判断是否为null、空格、制表符、换行符
		if (StringUtils.isBlank(ruleModels)) return null;
		return ruleModels.split(Constants.SPLIT);
	}

	public String getRuleWeight() {
		String[] ruleModels = this.ruleModels();
		for (String ruleModel : ruleModels) {
			if ("rule_weight".equals(ruleModel)) return ruleModel;
		}
		return null;
	}

}
